﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace MOTA_WP
{
    public class TopBar
    {
        /// <summary>
        /// Create a global application top bar;
        /// </summary>
        /// <param name="inputCanvas"></param>
        /// <param name="titleTetxt"></param>
        /// <param name="backDelegate"></param>
        /// <param name="rightBtnDelegate"></param>
        public void createTopBar(Canvas inputCanvas, string titleTetxt, ClickDelegate backDelegate, ClickDelegate rightBtnDelegate)
        {
            // create topbar(stackPanel, it is a container)
            StackPanel topBar = new StackPanel();
            // set UI properties
            topBar.Width = 480;
            topBar.Height = 110;
            // set orientation
            topBar.Orientation = System.Windows.Controls.Orientation.Horizontal;

            // create background ImageSource
            ImageBrush tmpImgBrush = new ImageBrush();
            tmpImgBrush.ImageSource = new BitmapImage(new Uri(@"Images/topbar.png", UriKind.Relative));
            topBar.Background = tmpImgBrush;

            // create back button
            Button tmpBtn = new Button();
            // create background ImageSource
            ImageBrush btnBrush = new ImageBrush();
            btnBrush.ImageSource = new BitmapImage(new Uri(@"Images/bt_back.png", UriKind.Relative));
            tmpBtn.Background = btnBrush;   
            tmpBtn.Click += new RoutedEventHandler(backDelegate);

            // set UI properties
            tmpBtn.Width = 88;
            tmpBtn.Height = 88;
            tmpBtn.BorderBrush = new SolidColorBrush(Colors.Transparent);
            tmpBtn.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            tmpBtn.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

            // add to stackpanel(topbar)
            topBar.Children.Add(tmpBtn);

            // create a textblock
            TextBlock tmpTextBlock = new TextBlock();
            tmpTextBlock.Text = titleTetxt;

            // set UI properties
            tmpTextBlock.Width = 250;
            tmpTextBlock.Height = 70;
            tmpTextBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            tmpTextBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            tmpTextBlock.TextAlignment = TextAlignment.Left;
            tmpTextBlock.FontSize = 48;
            // add to stackPanel(topBar)
            topBar.Children.Add(tmpTextBlock);

            // create a button
            tmpBtn = new Button();

            // create background ImageSource
            btnBrush = new ImageBrush();
            btnBrush.ImageSource = new BitmapImage(new Uri(@"Images/bt_update.png", UriKind.Relative));
            tmpBtn.Background = btnBrush;


            // set UI properties
            tmpBtn.Width = 141;
            tmpBtn.Height = 70;
            tmpBtn.BorderBrush = new SolidColorBrush(Colors.Transparent);
            tmpBtn.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            tmpBtn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            tmpBtn.Click += new RoutedEventHandler(rightBtnDelegate);

            // add to stackPanel(topBar)
            topBar.Children.Add(tmpBtn);

            // add topBar to background Canvas
            inputCanvas.Children.Add(topBar);

            // set position of topBar(relative to Canvas)
            Canvas.SetLeft(topBar, 0);
            Canvas.SetTop(topBar, 0);
        }

        private void BackBtn_Click(object sender, RoutedEventArgs e)
        {
               
        }
    }
}
